<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加用户</title>
    <link rel="stylesheet" href="../frame/layui/css/layui.css">
    <link rel="stylesheet" href="../frame/static/css/style.css">
    <link rel="icon" href="../frame/static/image/code.png">
</head>
<body class="body">


<div class="layui-form-item">
    <label class="layui-form-label">用户名称:</label>

    <div class="layui-input-inline">
        <input type="text" id='wcode' autocomplete="off" placeholder="请输入名称"
               class="layui-input">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">金额:</label>

    <div class="layui-input-inline">
        <input type="text" id='balace' lay-verify="required" placeholder="金额"
               class="layui-input">
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">电话号码:</label>

    <div class="layui-input-inline">
        <input type="text" id='phone' lay-verify="required" placeholder="电话号码"
               class="layui-input">
    </div>
</div>
<div class="layui-form-item">
    <label class="layui-form-label">邀请人:</label>

    <div class="layui-input-inline">
        <input type="text" id='parent' lay-verify="required" placeholder="邀请人"
               class="layui-input">
    </div>
</div>


<div class="layui-layer-btn layui-layer-btn-c">
    <button class="layui-btn layui-btn-normal layui-btn-radius" onclick="createUser()">提交</button>
</div>


<script src="../frame/layui/layui.js" charset="utf-8"></script>
<script src="/lib/jquery-2.1.4.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use(['form', 'layedit', 'laydate', 'element'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , element = layui.element
            , $ = layui.jQuery;


    });


    function createUser() {
        var params = {
            "wcode": $("#wcode").val(),
            "balace": $("#balace").val(),
            "parent": $("#parent").val(),
            "phone": $("#phone").val(),

        }
        $.ajax({
            url: "/admin/createUser",
            type: "post",
            contentType: "application/json",
            data: JSON.stringify(params),
            success: function (result) {
                console.log(result)
                if (result.code === "200") {
                    alert("添加成功");
                    setTimeout(function () {
                        layer.closeAll('templates.index');
                    }, 3000);
                    parent.location.reload();

                } else {
                    alert("操作失败");

                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest.responseText);

            }
        });
    }

</script>
</body>
</html>